package com.cleaningcloud.erp.controller.mini;

import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.security.annotation.InnerAuth;
import com.cleaningcloud.erp.domain.dto.ErpSaleDto;
import com.cleaningcloud.erp.domain.vo.ErpSaleVo;
import com.cleaningcloud.erp.service.IErpSaleService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * packageName com.cleaningcloud.erp.controller.mini
 *
 * @author Shaw
 * @version JDK 8
 * @className MallOrderController
 * @date 2025-04-03
 * @description 三才环科商城(小程序)订单接口
 */
@RestController
@RequestMapping("/mall/order")
public class MallOrderController extends BaseController {

    @Autowired
    private IErpSaleService erpSaleService;

    /**
     * @Author Shaw
     * @Description 用户下单
     * @date: 2025-04-01 16:11
     * @param: //TODO
     */
    @InnerAuth
    @Operation(description = "用户下单")
    @PostMapping("/addOrderInfo")
    public AjaxResult addOrderInfo(@RequestBody ErpSaleDto erpSaleDto) {
        return toAjax(erpSaleService.insertMallErpSale(erpSaleDto));
    }

    /**
     * @Author Shaw
     * @Description 获取订单列表
     * @date: 2025-04-01 16:11
     * @param: //TODO
     */
    @InnerAuth
    @Operation(description = "获取订单列表")
    @GetMapping("/getOrderList")
    public TableDataInfo getOrderList(ErpSaleDto erpSaleDto) {
        startPage();
        List<ErpSaleVo> list = erpSaleService.getMallSaleList(erpSaleDto);
        return getMiniDataTable(list);
    }

    /**
     * @Author Shaw
     * @Description 根据订单ID查询详情信息
     * @date: 2025-04-01 16:11
     * @param: //TODO
     */
    @InnerAuth
    @Operation(description = "根据订单ID查询详情信息")
    @GetMapping("/queryOrderInfo")
    public AjaxResult queryOrderInfo(ErpSaleDto erpSaleDto) {
        return success(erpSaleService.getMallSaleInfo(erpSaleDto));
    }

    /**
     * @Author Shaw
     * @Description 订单取消
     * @date: 2025-04-01 16:11
     * @param: //TODO
     */
    @InnerAuth
    @Operation(description = "订单取消")
    @PostMapping("/cancelOrder")
    public AjaxResult cancelOrder(ErpSaleDto erpSaleDto) {
        return toAjax(erpSaleService.cancelOrder(erpSaleDto));
    }
}